package cn.tedu.csmall.product.config;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;

/**
 * @Description:
 * @Author: sweeterjava@163.com
 * @Date: 2022/11/1
 * @Time: 14:12
 */

@Slf4j
@Configuration
public class ValidationConfiguration {
    public ValidationConfiguration() {
        log.debug("创建配置类对象：ValidationConfiguration");
    }

    // Builder模式
    // 链式语法
    @Bean
    public javax.validation.Validator validator(){
        return Validation.byProvider(HibernateValidator .class)
                .configure()// 配置
                .failFast(true) // 快速失败模式，即检查请求参数时，一旦发现错误，立即返回错误信息，不再继续检查，提高效率
                .buildValidatorFactory()
                .getValidator();
    }


}
